home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / sndhrdw / targ.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  4KB  |  163 lines

  1. /* Sound channel usage
  2.    0 = CPU music,  Shoot
  3.    1 = Crash
  4.    2 = Spectar sound
  5.    3 = Tone generator
  6. */
  7.  
  8. #include "driver.h"
  9.  
  10. static int tone_channel;
  11.  
  12. unsigned char targ_spec_flag;
  13. static unsigned char targ_sh_ctrl0=0;
  14. static unsigned char targ_sh_ctrl1=0;
  15. static unsigned char tone_active;
  16.  
  17. #define MAXFREQ_A_TARG 125000
  18. #define MAXFREQ_A_SPECTAR 525000
  19.  
  20. static int sound_a_freq;
  21. static unsigned char tone_pointer;
  22. static unsigned char tone_offset;
  23.  
  24. static unsigned char tone_prom[32] =
  25. {
  26.     0xE5,0xE5,0xED,0xED,0xE5,0xE5,0xED,0xED,0xE7,0xE7,0xEF,0xEF,0xE7,0xE7,0xEF,0xEF,
  27.     0xC1,0xE1,0xC9,0xE9,0xC5,0xE5,0xCD,0xED,0xC3,0xE3,0xCB,0xEB,0xC7,0xE7,0xCF,0xEF
  28. };
  29.  
  30. /* waveforms for the audio hardware */
  31. static unsigned char waveform1[32] =
  32. {
  33.     /* sine-wave */
  34.     0x0F, 0x0F, 0x0F, 0x06, 0x06, 0x09, 0x09, 0x06, 0x06, 0x09, 0x06, 0x0D, 0x0F, 0x0F, 0x0D, 0x00,
  35.     0xE6, 0xDE, 0xE1, 0xE6, 0xEC, 0xE6, 0xE7, 0xE7, 0xE7, 0xEC, 0xEC, 0xEC, 0xE7, 0xE1, 0xE1, 0xE7,
  36. };
  37.  
  38. /* some macros to make detecting bit changes easier */
  39. #define RISING_EDGE(bit)  ((data & bit) && !(targ_sh_ctrl0 & bit))
  40. #define FALLING_EDGE(bit) (!(data & bit) && (targ_sh_ctrl0 & bit))
  41.  
  42.  
  43. void targ_tone_generator(int data)
  44. {
  45.     int maxfreq;
  46.  
  47.  
  48.     if (targ_spec_flag) maxfreq = MAXFREQ_A_TARG;
  49.     else maxfreq = MAXFREQ_A_SPECTAR;
  50.  
  51.     sound_a_freq = data;
  52.     if (sound_a_freq == 0xFF || sound_a_freq == 0x00)
  53.     {
  54.         mixer_set_volume(tone_channel,0);
  55.     }
  56.     else
  57.     {
  58.         mixer_set_sample_frequency(tone_channel,maxfreq/(0xFF-sound_a_freq));
  59.         mixer_set_volume(tone_channel,tone_active*100);
  60.     }
  61. }
  62.  
  63. int targ_sh_start(const struct MachineSound *msound)
  64. {
  65.     tone_channel = mixer_allocate_channel(50);
  66.  
  67.     tone_pointer=0;
  68.     tone_offset=0;
  69.     tone_active=0;
  70.     sound_a_freq = 0x00;
  71.     mixer_set_volume(tone_channel,0);
  72.     mixer_play_sample(tone_channel,(signed char*)waveform1,32,1000,1);
  73.     return 0;
  74. }
  75.  
  76. void targ_sh_stop(void)
  77. {
  78.     mixer_stop_sample(tone_channel);
  79. }
  80.  
  81. WRITE_HANDLER( targ_sh_w )
  82. {
  83.     int maxfreq;
  84.  
  85.  
  86.     if (targ_spec_flag) maxfreq = MAXFREQ_A_TARG;
  87.     else maxfreq = MAXFREQ_A_SPECTAR;
  88.  
  89.     if (offset) {
  90.         if (targ_spec_flag) {
  91.             if (data & 0x02)
  92.                 tone_offset=16;
  93.             else
  94.                 tone_offset=0;
  95.  
  96.             if ((data & 0x01) && !(targ_sh_ctrl1 & 0x01)) {
  97.                 tone_pointer++;
  98.                 if (tone_pointer > 15) tone_pointer = 0;
  99.                 targ_tone_generator(tone_prom[tone_pointer+tone_offset]);
  100.             }
  101.        }
  102.        else {
  103.             targ_tone_generator(data);
  104.        }
  105.        targ_sh_ctrl1=data;
  106.     }
  107.     else
  108.     {
  109.         /* cpu music */
  110.         if ((data & 0x01) != (targ_sh_ctrl0 & 0x01)) {
  111.             DAC_data_w(0,(data & 0x01) * 0xFF);
  112.         }
  113.         /* Shoot */
  114.         if FALLING_EDGE(0x02) {
  115.             if (!sample_playing(0))  sample_start(0,1,0);
  116.         }
  117.         if RISING_EDGE(0x02) {
  118.             sample_stop(0);
  119.         }
  120.  
  121.         /* Crash */
  122.         if RISING_EDGE(0x20) {
  123.             if (data & 0x40) {
  124.                 sample_start(1,2,0); }
  125.             else {
  126.                 sample_start(1,0,0); }
  127.         }
  128.  
  129.         /* Sspec */
  130.         if (data & 0x10) {
  131.             sample_stop(2);
  132.         }
  133.         else {
  134.             if ((data & 0x08) != (targ_sh_ctrl0 & 0x08)) {
  135.             if (data & 0x08) {
  136.                 sample_start(2,3,1); }
  137.             else {
  138.                 sample_start(2,4,1); }
  139.             }
  140.         }
  141.  
  142.         /* Game (tone generator enable) */
  143.         if FALLING_EDGE(0x80) {
  144.            tone_pointer=0;
  145.            tone_active=0;
  146.            if (sound_a_freq == 0xFF || sound_a_freq == 0x00)
  147.            {
  148.                 mixer_set_volume(tone_channel,0);
  149.            }
  150.            else
  151.            {
  152.              mixer_set_sample_frequency(tone_channel,maxfreq/(0xFF-sound_a_freq));
  153.              mixer_set_volume(tone_channel,0);
  154.            }
  155.         }
  156.         if RISING_EDGE(0x80) {
  157.             tone_active=1;
  158.         }
  159.         targ_sh_ctrl0 = data;
  160.     }
  161. }
  162.  
  163.